﻿#include "textsettingdlg.h"
#include "ui_textsettingdlg.h"

#include <QFontDialog>
#include <QColorDialog>

TextSettingDlg::TextSettingDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::TextSettingDlg),
    m_font("Microsoft YaHei",40)
{
    ui->setupUi(this);
    showFontInfo();

    ui->sb_x->setVisible(false);
    ui->sb_y->setVisible(false);
}

TextSettingDlg::~TextSettingDlg()
{
    delete ui;
}

void TextSettingDlg::showFontInfo()
{
    ui->lb_font->setText( QString("%1,%2").arg(m_font.family()).arg(m_font.pointSize()) );
}

void TextSettingDlg::on_pb_font_clicked()
{
    bool isOk = false;

    QFont font = QFontDialog::getFont(&isOk,m_font,this);
    if(isOk){
        m_font = font;
        showFontInfo();
    }
}

CBType TextSettingDlg::HType() const
{
    return m_HType;
}

CBType TextSettingDlg::VType() const
{
    return m_VType;
}

QString TextSettingDlg::text() const
{
    return ui->lineEdit->text();
}

QPoint TextSettingDlg::point() const
{
    return QPoint(ui->sb_x->value(),ui->sb_y->value());
}

QFont TextSettingDlg::textFont() const
{
    return m_font;
}

QColor TextSettingDlg::color() const
{
    return m_color;
}

void TextSettingDlg::on_cb_h_currentIndexChanged(int index)
{
    m_HType = CBType((int)H_CENTER + index);
    if(index == 3){
        ui->sb_x->setVisible(true);
    }else{
        ui->sb_x->setVisible(false);
    }
}

void TextSettingDlg::on_cb_v_currentIndexChanged(int index)
{
    m_VType = CBType(index);
    if(index == 3){
        ui->sb_y->setVisible(true);
    }else{
        ui->sb_y->setVisible(false);
    }
}

void TextSettingDlg::on_pb_color_clicked()
{
    auto color = QColorDialog::getColor(Qt::black,this,QStringLiteral("Select color"));
    auto str = QString("background-color: %1;")
            .arg(color.name());

    ui->lb_color->setStyleSheet(str);
    m_color = color;
}
